/**
 * 
 */
package com.gmail.blackdog1987.carcare.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gmail.blackdog1987.carcare.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.carcare.service.CountService;
import com.gmail.blackdog1987.carcare.util.ErrorCode;

/**
 * 
 * @author 董国超
 * 
 */
@Service("countService")
public class CountServiceImpl implements CountService {

	@Autowired
	private BaseJdbcDao baseJdbcDao;

	@Override
	public Map<String, Object> getCarSaleCount(Map<String, String> filter) {
		Map<String, Object> result = new HashMap<String, Object>();

		result.put("code", ErrorCode.NO);

		// 按类型，品牌，车系
		Integer types = baseJdbcDao
				.getJdbcTemplate()
				.queryForInt(
						" select count(*) from (select * from t_car_sale where nation=0 group by type,band,series ) a ",
						new Object[] {});
		Integer forignTypes = baseJdbcDao
				.getJdbcTemplate()
				.queryForInt(
						" select count(*) from (select * from t_car_sale where nation=1 group by type,band,series ) a ",
						new Object[] {});

		Integer cars = baseJdbcDao.getJdbcTemplate().queryForInt(
				" select count(*) from t_car_sale where nation = 0 ",
				new Object[] {});
		Integer forignCars = baseJdbcDao.getJdbcTemplate().queryForInt(
				" select count(*) from t_car_sale where nation = 1 ",
				new Object[] {});

		Map<String, Integer> count = new HashMap<String, Integer>();
		count.put("types", types);
		count.put("cars", cars);
		count.put("forignTypes", forignTypes);
		count.put("forignCars", forignCars);

		result.put("result", count);

		return result;
	}
}
